package com.example.tests;

import java.util.Collections;
import java.util.List;
import static org.testng.Assert.assertEquals;

import org.testng.annotations.Test;

public class ContactCreationTests extends TestBase
{
	@Test(dataProvider = "randomValidContactGenerator")
	public void testContactCreationWithValidData(ContactData contact) throws Exception
	{
		app.navigationTo().mainPage();
		
		//save old state
		List<ContactData> oldList = app.getContactHelper().getContacts();
		
		app.navigationTo().page("add new");

		//actions
		app.getContactHelper().fillContactForm(contact);
		app.getContactHelper().submitCreation();
		app.navigationTo().returnToPage("home page");
				
		//save new state
		List<ContactData> newList = app.getContactHelper().getContacts();
		
		//compare states
		oldList.add(contact);
		
		Collections.sort(oldList);		
		Collections.sort(newList);
		assertEquals(newList, oldList);
	}
}
